// OutlookUIDemoView.cpp : implementation of the COutlookUIDemoView class
//

#include "stdafx.h"
#include "OutlookUIDemo.h"

#include "OutlookUIDemoDoc.h"
#include "OutlookUIDemoView.h"
#include "ContainerView.h"
#include "FolderListView.h"
#include "PreviewPane.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COutlookUIDemoView

IMPLEMENT_DYNCREATE(COutlookUIDemoView, CView)

BEGIN_MESSAGE_MAP(COutlookUIDemoView, CView)
	//{{AFX_MSG_MAP(COutlookUIDemoView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_MESSAGE(FM_CLOSEFOLDERLISTVIEW, OnCloseFolderListView)
	ON_MESSAGE(CM_ONPUSHPINBUTTON, OnPushPinButton)
	ON_MESSAGE(CM_ONPUSHPINCANCEL, OnPushPinCancel)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COutlookUIDemoView construction/destruction

COutlookUIDemoView::COutlookUIDemoView()
{
	// define the caption font.
	NONCLIENTMETRICS ncm;
	memset(&ncm, 0, sizeof(NONCLIENTMETRICS));
	ncm.cbSize = sizeof(NONCLIENTMETRICS);

	VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
		sizeof(NONCLIENTMETRICS), &ncm, 0));
	ncm.lfMessageFont.lfWeight = 700;
	ncm.lfMessageFont.lfHeight = 20;
	strcpy(ncm.lfMessageFont.lfFaceName, "Arial");
	m_CaptionFont.CreateFontIndirect(&ncm.lfMessageFont);

	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

COutlookUIDemoView::~COutlookUIDemoView()
{
}

BOOL COutlookUIDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CView::PreCreateWindow(cs) )
		return FALSE;

	cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
	cs.dwExStyle |=  WS_EX_STATICEDGE;

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// COutlookUIDemoView drawing

void COutlookUIDemoView::OnDraw(CDC* pDC)
{
	COutlookUIDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

void COutlookUIDemoView::OnInitialUpdate()
{
	CView::OnInitialUpdate();

	// TODO: This code navigates to a popular spot on the web.
	//  change the code to go where you'd like.

}

/////////////////////////////////////////////////////////////////////////////
// COutlookUIDemoView printing


/////////////////////////////////////////////////////////////////////////////
// COutlookUIDemoView diagnostics

#ifdef _DEBUG
void COutlookUIDemoView::AssertValid() const
{
	CView::AssertValid();
}

void COutlookUIDemoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

COutlookUIDemoDoc* COutlookUIDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COutlookUIDemoDoc)));
	return (COutlookUIDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// COutlookUIDemoView message handlers

int COutlookUIDemoView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!m_Caption.Create(this, _T("Inbox")))
	{
		TRACE0(_T("Failed to caption window.\n"));
		return -1;
	}

	// set the caption colors.
	m_Caption.SetCaptionColors( ::GetSysColor(COLOR_BTNFACE),
		::GetSysColor(COLOR_BTNSHADOW), ::GetSysColor(COLOR_WINDOW));

	// set the caption style.
	m_Caption.ModifyCaptionStyle( 4, &m_CaptionFont, NULL, m_hIcon);

	// The context information is passed on from the framework
	CCreateContext *pContext = (CCreateContext*)lpCreateStruct->lpCreateParams;

	// Create the splitter window with two columns
	if (!m_wndSplitter.CreateStatic(this, 1, 2))
	{
		TRACE0("Failed to create splitter window\n");
		return FALSE;
	}

	if (!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CFolderListView),
		CSize(175, 0), pContext))
	{
		m_wndSplitter.DestroyWindow();
		return -1;
	}

	// add the third splitter pane - which is a nested splitter with 2 rows
	if (!m_wndSplitter2.CreateStatic(&m_wndSplitter,	// our parent window is the first splitter
		2, 1,											// the new splitter is 2 rows, 1 column
		WS_CHILD | WS_VISIBLE | WS_BORDER,				// style, WS_BORDER is needed
		m_wndSplitter.IdFromRowCol(0, 1)))				// new splitter is in the first row, 3rd column of first splitter
	{
		TRACE0("Failed to create nested splitter\n");
		return FALSE;
	}

	// now create the two views inside the nested splitter
	if (!m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(CContainerView),
		CSize(0, 300), pContext))
	{
		m_wndSplitter2.DestroyWindow();
		return FALSE;
	}

	if (!m_wndSplitter2.CreateView(1, 0, RUNTIME_CLASS(CPreviewPane),
		CSize(0, 0), pContext))
	{
		m_wndSplitter2.DestroyWindow();
		return FALSE;
	}

	// it all worked, we now have two splitter windows which contain
	// four different views
	
	return 0;
}

void COutlookUIDemoView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	if( m_wndSplitter.GetSafeHwnd())
	{
		int nCX = ::GetSystemMetrics( SM_CXEDGE );
		int nCY = ::GetSystemMetrics( SM_CYEDGE );
		
		// move and grow view to clip border
		m_wndSplitter.MoveWindow(-nCX, 30, cx+(nCX*2), cy+(nCY*2)-34);	
	}

	if( m_Caption.GetSafeHwnd()) {
		m_Caption.MoveWindow(0,0,cx,31);
	}
}

//void COutlookUIDemoView::OnCloseFolderListView(UINT lParam, LONG wParam)
LRESULT COutlookUIDemoView::OnCloseFolderListView(WPARAM lParam, LPARAM wParam)
{
	m_Caption.SetChildWindow( &CFolderListView::m_TreeCtrl, this );
	m_wndSplitter.HideColumn(0);
	return TRUE;
}

//void COutlookUIDemoView::OnPushPinButton(UINT lParam, LONG wParam)
LRESULT COutlookUIDemoView::OnPushPinButton(WPARAM lParam, LPARAM wParam)
{
	m_wndSplitter.ShowColumn();
	return TRUE;
}

//void COutlookUIDemoView::OnPushPinCancel(UINT lParam, LONG wParam)
LRESULT COutlookUIDemoView::OnPushPinCancel(WPARAM lParam, LPARAM wParam)
{
	// TODO: Add your message handler code here and/or call default
	return TRUE;
}

CCJTreeCtrl* COutlookUIDemoView::GetFolderTreeCtrl()
{
	return &CFolderListView::m_TreeCtrl;
}
